package com.example.barcodeapp.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.R;

import java.util.ArrayList;

public class YouHuiJunAdapter extends RecyclerView.Adapter<YouHuiJunAdapter.ViewHolder> {
    private Context context;
    private ArrayList<Boolean> list;

    public YouHuiJunAdapter(Context context, ArrayList<Boolean> list) {
        this.context = context;
        this.list = list;
    }

    public YouHuiJunAdapter(Context context) {
        this.context = context;
    }

    private YouHuiJunAdapter.IClick callback;
    public void setClick(YouHuiJunAdapter.IClick cb){
        callback = cb;
    }
    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_youhuijuan, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {

        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                callback.click(position);
            }
        });
        if (list.get(position)){
            Glide.with(context).load(R.mipmap.click1).into(holder.zhuangtai);
        }else {
            Glide.with(context).load(R.mipmap.not).into(holder.zhuangtai);
        }


    }

    @Override
    public int getItemCount() {
        return 2;
    }


    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView11;
        private ImageView zhuangtai;
        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView11 = (ImageView) itemView.findViewById(R.id.imageView11);
            zhuangtai = (ImageView) itemView.findViewById(R.id.zhuangtai);
        }
    }

    public interface IClick{
        void click(int pos);
    }

}
